<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图  -->
    <el-card>
      <el-form>
        <el-row>
          <el-col :span="8">
            <el-form-item label="内容" width="120px">
              <el-input placeholder="请输入内容" clearable v-model.trim="form.query" @clear="getList('1')"> </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-button type="primary" @click="query('1')">查询</el-button>
          </el-col>
        </el-row>
      </el-form>
      <!-- 列表 -->
      <el-table :data="tableData" border stripe>
        <el-table-column label="订单编号" prop="order_number"> </el-table-column>
        <el-table-column label="订单价格" prop="order_price"> </el-table-column>
        <el-table-column label="是否付款" prop="order_pay">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.order_pay == 0">未付款</el-tag>
            <el-tag type="success" v-if="scope.row.order_pay == 1">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"> </el-table-column>
        <el-table-column label="下单时间" prop="create_time">
          <template slot-scope="scope">
            {{ scope.row.create_time | dataFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="140px">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="编辑地址" placement="top-start">
              <el-button type="primary" size="mini" icon="el-icon-edit" @click.native="editAddr(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="物流进度" placement="top-start">
              <el-button type="success" size="mini" icon="el-icon-location-outline" @click.native="showProcess(scope.row)"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[10, 20, 30]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      >
      </el-pagination>
    </el-card>
    <!-- 修改地址 -->
    <el-dialog title="修改地址" :visible.sync="disalogAddrVisible" label-width="120px" @close="closeAddr">
      <el-form :model="addressForm" :rules="rules" ref="addressForm" label-width="100px">
        <el-form-item label="省市区" prop="address1">
          <el-cascader :options="cityDate" v-model="addressForm.address1" clearable :props="propCascaderObj"> </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit('addressForm')">确定</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>

      <span slot="footer">
        <el-button @click="disalogAddrVisible = false">取消</el-button>
        <el-button type="primary">确定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="物流进度" :visible.sync="disalogProcessVisible">
      <el-timeline>
        <el-timeline-item v-for="(activity, index) in processInfo" :key="index" :timestamp="activity.time">
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityDate from '@/assets/js/cityDate.js'
export default {
  data() {
    return {
      form: {
        query: ''
      },
      pageNum: 1,
      pageSize: 10,
      total: 0,
      tableData: [],
      //修改地址
      disalogAddrVisible: false,
      addressForm: {
        address1: [],
        address1: ''
      },
      rules: {
        address1: [{ required: true, message: '请选择省市区', trigger: 'blur,change' }],
        address2: [{ required: true, message: '请填写详细地址', trigger: 'blur' }]
      },
      cityDate: cityDate, //地址列表
      propCascaderObj: {
        //级联配置项
        expandTrigger: 'hover',
        value: 'value',
        label: 'label',
        children: 'children'
      },
      disalogProcessVisible: false, //物流进度
      processInfo: [
        {
          time: '2018-05-10 09:39:00',
          ftime: '2018-05-10 09:39:00',
          context: '已签收,感谢使用顺丰,期待再次为您服务',
          location: ''
        },
        {
          time: '2018-05-10 08:23:00',
          ftime: '2018-05-10 08:23:00',
          context: '[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件',
          location: ''
        }
      ]
    }
  },
  mounted() {
    this.getList('1')
  },
  methods: {
    getList(type) {
      //获取订单列表
      if (type == '1') {
        this.pageNum = 1
        this.pageSize = 10
      }
      const data = {
        query: this.form.query,
        pagenum: this.pageNum,
        pagesize: this.pageSize
      }
      this.$http
        .get('/orders', { params: data })
        .then(res => {
          res = res.data
          // console.log(res)
          if (res.meta.status == 200) {
            this.tableData = res.data.goods
            this.total = res.data.total
            console.log('tableData', this.tableData)
          } else {
            this.$message({ type: 'error', message: res.meta.msg })
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    editAddr(row) {
      //修改地址
      this.disalogAddrVisible = true
    },
    closeAddr() {
      this.$refs.addressForm.resetFields()
    },
    showProcess(row) {
      //展示物流进度
      this.disalogProcessVisible = true
      // this.getKuaidi(row);
    },
    getKuaidi(row) {
      // const order_number=row.order_number
      const order_number = '1106975712662' //供测试的物流单号
      this.$http
        .get(`/kuaidi/${order_number}`)
        .then(res => {
          res = res.data
          // console.log(res)
          if (res.meta.status == 200) {
            this.processInfo = res.data
            console.log('processInfo', this.processInfo)
          } else {
            this.$message({ type: 'error', message: res.meta.msg })
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.pageNum = val
      this.getList()
    }
  }
}
</script>

<style scoped></style>
